package org.chenliang.emulator.ui;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

public class StatusBar extends Composite {
	private Map<Integer, Label> labels = new HashMap<Integer, Label>();
	public StatusBar(Composite parent, int style , int numLabels) {
		super(parent, style);
		
		GridLayout layout = new GridLayout(numLabels ,true);
		
		setLayout(layout);
		
		for(int i = 0 ;i < numLabels ;i ++){
			Label label = new Label(this , SWT.BORDER);
			
			GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
			gd.grabExcessHorizontalSpace = true;
			label.setLayoutData(gd);
			
			labels.put(i, label);
		}
		
		layout();
	}
	
	public void setText(int id , String message){
		int labelCount = labels.size();
		if(labelCount > 0){
			if(message != null && id >= 0 && id < labelCount){
				Label l = labels.get(id);
				l.setText(message);
				l.update();
			}
		}
	}
	public int getLabelCount(){
		return labels.size();
	}
}
